﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.Specialized;

namespace Nighthawk
{
    /// <summary>
    /// Interaktionslogik für SettingsWindow.xaml
    /// </summary>
    public partial class SettingsWindow : Window
    {
        public SettingsWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SetAllAttributes();
        }

        private void SetAllAttributes()
        {
            //Sniffer
            StringCollection col = Properties.Settings.Default.userfields;
            StringCollection col2 = Properties.Settings.Default.passfields;
            StringCollection col3 = Properties.Settings.Default.exuserfields;
            StringCollection col4 = Properties.Settings.Default.expassfields;
            foreach (string user in col)
            {
                textBox2.AppendText(user + "\n");
            }
            foreach (string pass in col2)
            {
                textBox3.AppendText(pass + "\n");
            }
            foreach (string exuser in col3)
            {
                textBox4.AppendText(exuser + "\n");
            }
            foreach (string expass in col4)
            {
                textBox5.AppendText(expass + "\n");
            }
            //History
            slider1.Value = Properties.Settings.Default.shortlimit;
            label6.Content = Properties.Settings.Default.shortlimit;
            slider2.Value = Properties.Settings.Default.TimeFilter;
            label8.Content = Properties.Settings.Default.TimeFilter;
            slider3.Value = Properties.Settings.Default.extremeshortlimit;
            label10.Content = Properties.Settings.Default.extremeshortlimit;
            StringCollection col1 = Properties.Settings.Default.notinterestingsites;
            string [] uninteresting=new string[col1.Count];
            col1.CopyTo(uninteresting, 0);
            foreach (string wert in uninteresting)
            {
                textBox1.AppendText(wert + "\n");
            }
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            label6.Content = e.NewValue;
        }

        private void slider2_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            label8.Content = e.NewValue;
        }

        private void slider3_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            label10.Content = e.NewValue;
        }

        private void buttonsave_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("If things have been changed you will have to restart the module!", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            
            //Sliders
            Properties.Settings.Default.shortlimit = (int)slider1.Value;
            Properties.Settings.Default.TimeFilter = (int)slider2.Value;
            Properties.Settings.Default.extremeshortlimit = (int)slider3.Value;
            
            
            //Boxes
            string[] text1 = textBox1.Text.Split(new Char []{});
            Properties.Settings.Default.notinterestingsites.Clear();
            Properties.Settings.Default.notinterestingsites.AddRange(text1);

            string[] text2 = textBox2.Text.Split(new Char[] { });
            Properties.Settings.Default.userfields.Clear();
            Properties.Settings.Default.userfields.AddRange(text2);
            
            string[] text3 = textBox3.Text.Split(new Char[] { });
            Properties.Settings.Default.passfields.Clear();
            Properties.Settings.Default.passfields.AddRange(text3);

            string[] text4 = textBox4.Text.Split(new Char[] { });
            Properties.Settings.Default.exuserfields.Clear();
            Properties.Settings.Default.exuserfields.AddRange(text4);

            string[] text5 = textBox5.Text.Split(new Char[] { });
            Properties.Settings.Default.expassfields.Clear();
            Properties.Settings.Default.expassfields.AddRange(text5);
            
            Properties.Settings.Default.Save();
            this.Close();
        }
    }
}
